<?php
if ((($_FILES["file"]["type"] == "audio/midi") ||
     ($_FILES["file"]["type"] == "audio/x-midi") ||
	 ($_FILES["file"]["type"] == "audio/mid") ||
	 ($_FILES["file"]["type"] == "application/x-midi"))
 && (($_FILES["key"]["type"] == "audio/midi") ||
     ($_FILES["key"]["type"] == "audio/x-midi") ||
	 ($_FILES["key"]["type"] == "audio/mid") ||
	 ($_FILES["key"]["type"] == "application/x-midi"))) {
  if ($_FILES["file"]["error"] > 0) {
	echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  } elseif ($_FILES["key"]["error"] > 0) {
	echo "Return Code: " . $_FILES["key"]["error"] . "<br />";
  } else {
	$output_file = mt_rand(10000000,99999999) . ".mid";
	shell_exec("/bin/bash -c \"java MCS decrypt " . escapeshellarg($_FILES["key"]["tmp_name"]) . " " . escapeshellarg($output_file) . " " . escapeshellarg($_FILES["file"]["tmp_name"]) . "\"");
	header('Content-type: text/plain');
	header('Content-Disposition: attachment; filename="output.txt"');
	readfile($output_file);
	unlink($output_file);
  }
} else {
  echo "Invalid file";
}
?> 
